/**
 * version : weiAni 1.0;
 * author  : wuliang;
 */
// signal:信号 1:成功 2:失败
// 获取dom
function weiEle(selector){
    if(!selector){selector = document;}
    var selectorType = typeof(selector);
    switch(selectorType){
        case 'string':
        var doms = document.querySelectorAll(selector);
        var reObj = {dom:doms, length:doms.length};
        break;
        case 'object':
        var reObj = {dom:[selector], length:1};
        break;
        default:
        return null;
    }
    reObj.__proto__ = weiExtends;
    return reObj;
}
//增加dom操作的方法
var weiExtends = {
    length : function(){return this.length},
    /* 值、属性、HTML、操作 */
    val : function(vars){
        if(typeof(vars) != 'undefined'){for(var i = 0; i < this.length; i++){this.dom[i].value = vars;} return this;}
        try{return this.dom[0].value;}catch(e){console.log(_lang.domEmpty); return null;}
    },
    html : function(html){
        if(this.length < 1){return this;}
        if(typeof(html) != 'undefined'){for(var i = 0; i < this.length; i++){this.dom[i].innerHTML = html;} return this;}
        try{return this.dom[0].innerHTML;}catch(e){console.log(_lang.domEmpty); return null;}
    },
    attr:function(attrName, val){
        if(val){this.setAttr(attrName, val);}else{return this.getAttr(attrName);}
    },
    getAttr : function(attrName){
        try{return this.dom[0].getAttribute(attrName);}catch(e){console.log(_lang.domEmpty); return null;}
    },
    setAttr : function(attrName, val){
        for(var i = 0; i < this.length; i++){this.dom[i].setAttribute(attrName, val);} return this;
    },
    removeAttr : function(attrName){
        for(var i = 0; i < this.length; i++){this.dom[i].removeAttribute(attrName);}
        return this;
    },
    /* 样式操作 */
    css : function(csses){
        for(var i = 0; i < this.length; i++){var styles = this.dom[i].style; for(var k in csses){styles[k] = csses[k];}}
        return this;
    },
    hasClass : function(cls){
        if(this.length != 1){return false;}
        return this.dom[0].className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
    },
    addClass : function(cls){
        for(var i = 0; i < this.length; i++){
            if(!this.dom[i].className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'))){this.dom[i].className += " " + cls;}
        }
        return this;
    },
    removeClass : function(cls){
        var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
        for(var i = 0; i < this.length; i++){this.dom[i].className = this.dom[i].className.replace(reg, ' ');}
        return this;
    },
}
// 定时器部分
var renderTimeOut = function(fn,ms){
    if (typeof fn != 'function') {
        throwErr(fn+" is not function");
        return false
    }
    var timp = setTimeout(function(){
        fn()
        clearTimeout(timp)
    },ms || 700)
}
var throwErr = function(msg){
    throw(msg)
}